package com.example.sync.controller;

import com.example.sync.handler.impl.SysRabbitMQMessageSendHandler;
import com.example.sync.handler.impl.wrap.RabbitMQMessageWrap;
import com.example.utils.IdUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/*
 * @className: SysMQController
 * @author: chentao
 * @date: 2025/3/25 下午4:16
 * @Version: 1.0
 * @description:
 */
@RestController
public class SysRabbitMQController {

    @Resource
    private SysRabbitMQMessageSendHandler sysRabbitMQMessageSendHandler;

    /***
     * 发送mq消息
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "send")
    public String send(@RequestParam(defaultValue = "sitc.update.exchange") String exchange, @RequestParam(defaultValue = "user.update") String routingKey) throws Exception {
        String uuid = IdUtils.getId();
        RabbitMQMessageWrap rabbitMQMessageWrap = new RabbitMQMessageWrap(exchange, routingKey, uuid);
        sysRabbitMQMessageSendHandler.publish("com.example.user.SysUser", 1L, "user.add.mq.notify", rabbitMQMessageWrap.getClass().getName(), rabbitMQMessageWrap);
        return uuid;
    }
}
